/*
Unit Card Example
*/

var abilities = [
	{
		name: "Example Ability 2",
		desc: "Another example, this time using a utility function that adds all abilities described by objects in an array",
		onUse: function(ability, unit, user, target) {
			debug("Ability 2 is used!");
			return true;
		}
	},
	{
		name: "Ability 3",
		desc: "Hello world!",
		onUse: function(ability, unit, user, target) {
			debug("THIS IS ABILITY 3");
			return true;
		}
	}
];

function addAllAbilities(cardorunit, abilities) {
	abilities.forEach(function(a) {
		a.obj = cardorunit.addAbility(a.name, a.desc, a.targetflags || Targetable.NONE, a.onUse);
	});
}

// Called to setup the info about this particular card. Once this function has finished,
// it enters an immutable state and will stay so for the rest of its lifetime. (muahahahah!)
function setupCardData() {
	card.name = "Example Unit Card";
	card.desc = "An example unit card. Can be placed.";
	card.refId = "se.kayarr.examples.firstunit";
	card.maxHealth = 100;
	
	card.addAbility("Example Ability", "An example ability which can be used, added by directly calling addAbility", Targetable.NONE,
		function(ability, unit, user, target) {
			unit.session.narrate("Boing! Choo-choo!");
			return true;
		}
	);
	
	addAllAbilities(card, abilities);
}

// Per-unit initialization, called every time a new unit card instance is made - probably at the time the deck is generated.
// Unlike the card itself, the particular instances of the card can be modified at any time.
function onInit(unit) {
	unit.addAbility("Unit Ability", "An ability added as part of the unit only; can be used to make units with a dynamic set of abilities", Targetable.NONE,
		function(ability, unit, user, target) {
			debug("Unit-specific ability!");
			unit.session.narrate("Unit-specifics are cool!");
			return true;
		}
	);
	
	// unit.removeAbility(abilities[0].obj);
	
	debug("Aaaah " + unit.card.name);
}

function onPlaced(unit) {
}

function onRoundStart(unit) {
}

function onRoundEnd(unit) {
}